home *** CD-ROM | disk | FTP | other *** search
-
- /********************************************
- **** Animation Class Library V1.0 © 1994 Yves Schmid & Alia Development
- ****
- **** AnimBase.h
- ****
- **** Created: 12 May 1994
- **** Modified: 02 Septembre 1994
- **** Version: 0
- **** Compatible: C++, Mac System 7
- ****
- **** Description: AnimBase is the central object of the animation system, it handles
- **** timing, drawing, buffer and background.
- ****
- **** AnimBase is a child class of the AnimSupervisor class.
- ****
- *******************/
-
-
- #ifndef AnimBase_H
- #define AnimBase_H
-
-
- #include "AnimGfx.h"
- #include "Anim.h"
- #include "AnimPict.h"
- #include "AnimMask.h"
- #include "AnimCollision.h"
-
- typedef Boolean (*AnimCollisionFunc)(AnimObject*,AnimObject*);
-
- class AnimBase: public AnimSupervisor
- {
-
- //***********************************************************
- //.............. P U B L I C M E T H O D S.................
-
- public:
-
- AnimBase(void);
- ~AnimBase(void);
-
-
- virtual void preload_framedef(AnimFrameDef *def); // This method preloads
- // all datas of an AnimFrameDef in
- // memory. But the Anim is not built.
-
- virtual Boolean update(void); // If the tupdate has ellapsed starts to refresh
- // the display. It draws all animations, background
- // buffer, sorts anims, etc...
- // The most common way to use this method is to call
- // it repeatly in your event loop.
- // Returns TRUE if the update happends.
-
- virtual void updatewindow(void); // Call this method when your window need to be
- // updated.
-
-
-
- // If you call this method the next update will refresh the full screen. It is useful
- // when you draw something in the background AnimGfx.
-
- inline void forcefullrefresh(void) {needupdatefull=TRUE;}
-
-
- // Gets/sets your custom collision function. To stop collision destection simply
- // set the collision function to NULL:
- // "anim->setcollisionfunc(NULL);"
-
- inline AnimCollisionFunc getcollisionfunc(void) const {return collisionfunc;}
- inline void setcollisionfunc(const AnimCollisionFunc f) {collisionfunc = f;}
-
-
-
- inline short getsortflags(void) // These methods allow you set/get the sort flags
- {return sortflags;} // of animation objects under the control of
- // this AnimBase. See sort modes.
- inline void setsortflags(short f)
- {sortflags = f; if (f) sort();}
-
-
-
- inline void settupdate(const long t) {tupdate = t;}
- inline long gettupdate(void) const {return tupdate;}
- // These methods allow you set/get the
- // number of ticks to wait before
- // updating the display. By default
- // tupdate is initialised to 3
- // ticks. To have the maximum speed of
- // the computer set this
- // value to 0. Most of the time
- // it is not a good thing to set tupdate
- // to zero because your
- // animation may be too fast
- // if you use different
- // computers.
-
- void installbackground(long resID);
- void installbackground(AnimGfx *back); // Installs a background picture. You have to create
- // an AnimGfx. The AnimGfx will not be freed by
- // this object (unless you allocate the AnimGfx
- // with "newgfx"). Do not delete your AnimGfx
- // before removing it from the AnimBase!
- // You don't have to call "removebackground" before
- // installing a new background.
-
- void removebackground(void); // removes the background
- inline AnimGfx *getbackground() {return background;}
-
- void buildbuffer(short width, short height); // Builds an offscreen buffer to stop flickering
- // on screen. You set your buffer size to the same size
- // of your visual animation region in your window. If
- // you have a background installed, use
- // "buildbufferback" to have a buffer which
- // have the same size of your background.
- // You don't have to call removebuffer before
- // installing a new buffer of a different size.
-
- void removebuffer(void); // removes buffer
-
- void buildbufferback(void); // Same as "buildbuffer" but uses the background image to find
- // the size of the buffer. If there is no background this
- // method does nothing.
-
- virtual AnimGfx *newgfx(long resid, Boolean maybepurged =FALSE);
- // Builds an AnimGfx using a pict resource id. The AnimGfx
- // is added to an internal list of the AnimBase so you
- // don't have to worry about deleting the object. AnimBase
- // keeps trace of the resource IDs for each created
- // images, so it never duplicates a picture in memory.
- // If "newgfx" finds that AnimBase has an AnimGfx
- // in memory which comes from the same resource,
- // it returns the previous AnimGfx
- // without allocating a new one.
- // If "maybepurged" is TRUE this picture may be deleted
- // by "deleteunusedgfx" else this picture may only be delete
- // by yourself or when you delete this AnimBase.
- // A mask is created for the AnimGfx.
-
-
- virtual void deleteunusedgfx(void); // This method frees all graphics which are not used
- // anymore in this AnimBase. The function checks all
- // animations and background. If a picture is not used in
- // animations or background the picture will be
- // deleted. Note that this method will free AnimGfx
- // that you allocate yourself using "newgfx" only if
- // you pass TRUE to "maybepurged". Currently this method is
- // never called by the Anim Class Library. It's up to you
- // to call it when you think there are unused graphics
- // loaded in memory.
-
-
- inline short getbasex(void) const {return basex;} // Gets/sets basex and basey
- inline short getbasey(void) const {return basey;}
- inline void setbasex(const short x) {basex = x;}
- inline void setbasey(const short y) {basey = y;}
-
- AnimBase *getanimbase(void); // Returns "this"
-
-
-
-
- //***********************************************************
-
- //..........................................................
- // You should not call the following methods!
-
- virtual void docollision(void);
- virtual void sort(void);
-
-
- void exstartrefbuild(void);
- void exaddrefreshrect(Rect *r);
- void exobtainresult(Rect **rtab, long *tabsiz);
- void exupdateaddrect(Rect &r);
-
-
- //.....................
-
- protected:
- Boolean needupdatefull;
- Boolean nopartialupdate;
-
- //.....................
-
- protected:
-
- virtual void updatebackground(void);
-
- inline AnimGfx *getbuffer(void) {return buffer;}
-
-
- private:
-
- short basex,basey;
-
-
- AnimGfx *background;
-
- AnimGfx *buffer;
-
- long tupdate;
- long lasttupdate;
-
- short sortflags;
-
- AnimCollisionFunc collisionfunc;
-
-
- // Private methods
- AnimObject *findsupcollision(AnimObject *anim);
- AnimObject *findnextcollision(AnimObject *anim);
- Boolean loopcollision2(AnimObject *anim, AnimObject *coanim);
- Boolean loopcollision1(AnimObject *anim);
-
-
- //.....................................
- // Used by the refresh system. Private.
-
- Boolean refreshing;
- long refreshnused[4];
- long refreshstacksize;
- Rect *refreshstack[4];
- short currentstack;
-
- long addrefreshrect(long rstack);
- void purgeallrefreshrect(long rstack);
- void newrefreshrect(Rect *newr, long rstack);
- void processrefresh(long rstack, AnimGfx *source);
- void deleterefreshrect(unsigned long delp, long rstack);
- void unionallrefresh(unsigned long newp, long rstack);
- };
-
-
- //********** Sort Modes *************
-
- // • These flags can be ORed:
-
- #define ASORT_NULL 0 // Don't sort animations.
-
- #define ASORT_PRIORITY 0x0100 // Uses the priority field of the anim class.
- // The higher priority is drawn in front of
- // others.
- // If this flag is ORed with an exclusive flag,
- // it is first checked. If priority is equal
- // then AnimBase checks the exclusive flag.
-
- // • Following flags are exclusive (but they can be ORed with previous!).
-
- #define ASORT_BOTTOMRIGHT 1 // Animations which have the higher vertical position
- // are in front of the others. If two animations have
- // the same vertical positions, it's the higher horizontal
- // position which is draw in front of the other.
-
- #define ASORT_BOTTOMLEFT 2 // Animations which have the higher vertical position
- // are in front of the others. If two animations have
- // the same vertical positions, it's the smaller horizontal
- // position which is draw in front of the other.
-
- #define ASORT_TOPRIGHT 3 // Animations which have the smaller vertical position
- // are in front of the others. If two animations have
- // the same vertical positions, it's the higher horizontal
- // position which is drawn in front of the other.
-
- #define ASORT_TOPLEFT 4 // Animations which have the smaller vertical position
- // are in front of the others. If two animations have
- // the same vertical positions, it's the smaller horizontal
- // position which is drawn in front of the other.
-
- #define ASORT_RIGHTBOTTOM 5 // Animations which have the higher horizontal position
- // are in front of the others. If two animations have
- // the same horizontal positions, it's the higher vertical
- // position which is drawn in front of the other.
-
- #define ASORT_RIGHTTOP 6 // Animations which have the higher horizontal position
- // are in front of the others. If two animations have
- // the same horizontal positions, it's the smaller vertical
- // position which is drawn in front of the other.
-
- #define ASORT_LEFTBOTTOM 7 // Animations which have the smaller horizontal position
- // are in front of the others. If two animations have
- // the same horizontal positions, it's the higher vertical
- // position which is drawn in front of the other.
-
- #define ASORT_LEFTTOP 8 // Animations which have the smaller horizontal position
- // are in front of the others. If two animations have
- // the same horizonal positions, it's the smaller vertical
- // position which is drawn in front of the other.
-
-
-
- //***********************
- // These commands and structures are for internal usage, you should not have to use them
-
- #define animcmd_ISANIMGFXUSED 950
-
- struct acmdstruct_Searchagfxused
- {
- AnimGfx *agfx;
- Boolean used;
- };
-
- #define animcmd_FRAMEDELETED 951
-
-
- #endif
-
-